<?php
$this->breadcrumbs = array (
		'Clubes' => array (
				'index' 
		),
		$model->name 
);

$files = File::model ()->findAllByAttributes ( array (
		'type' => "TEAM",
		'relation_id' => $model->id 
) );
$file_list = array ();
foreach ( $files as $file ) {
	$file_list [] = array (
			'label' => $file->filename,
			'url' => array (
					'file',
					'filename' => $file->filename,
					'url' => $file->url 
			),
			'visible' => $_SESSION ['user']->username == 'admin' || $model->owner_id == $_SESSION ['owner']->id 
	);
}

$this->files = $file_list;

$this->menu = array (
		array (
				'label' => 'Listar Clubes',
				'url' => array (
						'index' 
				) 
		),
		array (
				'label' => 'Cadastar Clube',
				'url' => array (
						'create' 
				),
				'visible' => Team::model ()->findByAttributes ( array (
						'owner_id' => $_SESSION ['owner']->id 
				) ) == null 
		),
		array (
				'label' => 'Inserir Jogador',
				'url' => array (
						'/player/create',
						'team_id' => $model->id,
						'return_url' => '/team/view/' . $model->id 
				),
				'visible' => ($_SESSION ['user']->username == 'admin' || $model->owner_id == $_SESSION ['owner']->id) && $model->status == 'ATIVO' 
		),
		array (
				'label' => 'Aprovar Cadastro do Clube',
				'url' => '#',
				'visible' => $_SESSION ['user']->username == 'admin' && strtoupper($model->status) == 'EM APROVAÇÃO',
				'linkOptions' => array (
						'submit' => array (
								'approve',
								'id' => $model->id 
						),
						'confirm' => 'Deseja aprovar os dados do Clube?' 
				) 
		)
);

$photo = Utils::getTeamPhoto ( $model );

?>

<?php

if (strtoupper($model->status) == strtoupper("EM APROVAÇÃO")) {
	echo '<h4 align="right" style="color:orange;">' . $model->status . '</h4>';
}
?>

<table>
	<tr>
		<td>
	<?php echo CHtml::image(Utils::findImageUrl($photo[0]->filename),$model->name,array('width'=>120,'height'=>120)); ?>
</td>
		<td style="min-width: 500px;">
			<h1 align="center"><?php echo $model->name; ?></h1>
		</td>
	</tr>
</table>

<div> 
<?php if($model->categories != null && count($model->categories) > 0) { ?>
	<div class="span8 player_container" style="overflow: auto; max-height: 260px;">
		<h3 align='center'>Elenco</h3>
	<?php
	
	foreach ( $model->categories as $category ) {
		foreach ( $category->players as $player ) {
			//for($i = 0; $i < 20; $i ++) {
			if ($player->status == "ATIVO" || $_SESSION ['user']->username == 'admin' || $model->owner_id == $_SESSION ['owner']->id) {
				$photo = Utils::getPlayerPhoto ( $player );
				$color = 'green';
				if ($player->status != "ATIVO") {
					$color = 'rgb(44, 56, 116)';
				}
				echo "<span class='span1'><a href='" . Yii::app ()->getBaseUrl ( true ) . 
				"/index.php/player/view/" . $player->id . "' ><img src='" . Utils::findImageUrl ( $photo [0]->filename ) . 
				"' style='width:100px; height:150xp;' /><p align='center'><b style='color:" . $color . ";'>
				$player->nickname</b></p></a></span>";
			//}
			}
		}
	}
	?>
	</div>
	<?php } ?>
<br>
	<br>
</div>
<?php

$this->widget ( 'bootstrap.widgets.TbDetailView', array (
		'data' => $model,
		'attributes' => array (
				array (
						'label' => 'Proprietário',
						'value' => $model->owner->name 
				),
				'name',
				'official_name',
				'state',
				'city',
				'country',
				'street',
				'number',
				'complement',
				'neighborhood',
				'cep',
				'phone',
				'fax',
				'site',
				'email',
				'cnpjl',
				array (
						'label' => 'Data de Registro',
						'value' => $model->getDateTime () 
				),
				'federation',
				'mandato',
				'agency',
				'account',
				'bank',
	),
)); ?>
